package com.xinqi.modules.sys.appversion.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.modules.sys.appversion.dto.req.AppVersionCreateDTO;
import com.xinqi.modules.sys.appversion.dto.req.AppVersionQueryDTO;
import com.xinqi.modules.sys.appversion.dto.req.AppVersionUpdateDTO;
import com.xinqi.modules.sys.appversion.dto.rsp.AppVersionResultDTO;
import com.xinqi.modules.sys.appversion.service.AppVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Admin -- 版本记录
 *
 * @author: yyzhen
 * @date: 2023/03/31
 */
@Tag(name = "Admin-应用版本", description = "版本记录列表Admin接口")
@RestController
@RequestMapping("/admin/version")
@RequiredArgsConstructor
public class AppVersionAdminController {
    private final AppVersionService appVersionService;

    /**
     * 版本记录列表-分页
     */
    @Operation(summary = "版本记录列表-分页")
    @GetMapping("/page")
    public R<PageInfo<AppVersionResultDTO>> page(@ParameterObject AppVersionQueryDTO dto) {
        PageInfo<AppVersionResultDTO> page = appVersionService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 版本记录列表-详情
     */
    @Operation(summary = "版本记录列表-详情")
    @GetMapping("/{id}")
    public R<AppVersionResultDTO> findById(@PathVariable("id") Long id) {
        AppVersionResultDTO dto = appVersionService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增版本记录列表
     */
    @Operation(summary = "新增版本")
    @PostMapping
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 新增版本", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Long> insert(@RequestBody AppVersionCreateDTO dto) {
        return R.data(appVersionService.insert(dto));
    }

    /**
     * 修改版本记录列表
     */
    @Operation(summary = "修改版本")
    @PutMapping("/{id}")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 修改版本", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody AppVersionUpdateDTO dto) {
        dto.setId(id);
        return R.data(appVersionService.updateById(dto));
    }

    /**
     * 删除版本记录列表
     */
    @Operation(summary = "删除版本")
    @DeleteMapping("/{id}")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 删除版本", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(appVersionService.deleteById(id));
    }

}
